<?php
/*
	Version   :  1.2
	Created   :  20081002
	Modified  :  20091221
	Author    :  Pablo Ramirez
	co-Author :
	Descr     : Controlador "Service Types"
	Changelog : 1.0 - Version Inicial
				1.1 - Control de Acceso
				1.2 - Se crea funcion validateType para uso desde survey detail
*/
class ContainerTypesController extends AppController
{
	var $name      = 'ContainerTypes';
	var $helpers    = array('Html','Javascript','Ajax');
	
	function validateType($cot_codigo) {
		$this->layout = 'ajax';
		$this->ContainerType->id = $cot_codigo;
		$result = $this->ContainerType->read();
		if (!empty($result)) {
			$this->set('result', "OK");
			$this->set('type_detail', $result);
		} else {
		 	$this->set('result', "NOK");
		}
	}
	
	function index() {
		$this->checkSession('admin');
		$this->layout = 'maintenance';
		$cotArray = array();
		
		if (empty($this->data)) {
			$cots = $this->ContainerType->findAll(null,'*','cot_codigo ASC');
			foreach($cots as $cot) {
				$temp = array();
				foreach($cot['ContainerType'] as $key=>$value) {
					$temp[$key] = $value;
				}
				$cotArray[] = $temp;
			}
			$this->set('containerTypes', $cotArray);
		} 
	}
	
	function add($id = null) {
		$this->checkSession('admin');
		$this->layout = 'ajax';
		if (!empty($this->data)){
			if ($this->ContainerType->save($this->data)){
				$this->redirect('container_types'); 
			}
		} else {
			$this->set('id', $id);
		}
	}
	
	function edit($id = null) {
		$this->checkSession('admin');
		$this->layout = 'ajax';
		$this->ContainerType->id = $id;
		
		if (empty($this->data)){
			$this->data = $this->ContainerType->read();
			$this->set('id', $id);
		}else{
			if ($this->ContainerType->save($this->data)){
				//$this->Session->setFlash('Item Editado');
				$this->redirect('container_types');
			} else {
				$this->Session->setFlash('Error al editar el Item');
			}
		}
	}
	
	function view($id = null) {
		$this->checkSession('admin');
		$this->layout = 'ajax';
		$this->ContainerType->id = $id;
		
		if (empty($this->data)){
			//$this->set('owner', $this->ContainerType->read());
			$this->data = $this->ContainerType->read();
			$this->set('id', $id);
		}
	}
	
	function delete($id) {
		$this->checkSession('admin');
		if ($this->ContainerType->del($id)) { 
			$this->set('error', '0');
		} else {
			$this->set('error','1');
		}
		$this->redirect('container_types');
	
	}
	
}
?>